package com.xs.ahoi.hcxs.ui.dialog;

import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.view.Gravity;
import android.view.View;
import butterknife.OnClick;
import com.xs.ahoi.hcxs.R;
import com.xs.ahoi.hcxs.tencent.QQManager;
import com.xs.ahoi.hcxs.tencent.WXManager;
import com.xs.ahoi.hcxs.utils.Constants;

/**
 * 分享弹窗页面
 */
public class DialogShare extends BaseDialog {

    // 分享类型：文本，文件
    private Constants.ShareType shareType;
    private String textContent;
    private String filePath;
    private ShareListener shareListener;

    public DialogShare(@NonNull Context context) {
        super(context, R.style.common_dialog);
    }

    @Override
    public int getLayoutRes() {
        return R.layout.dialog_share;
    }

    @Override
    protected int showPosition() {
        return Gravity.BOTTOM;
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initListener() {

    }

    @Override
    protected void onStart() {
        super.onStart();
        updateView();
    }

    // 更新视图
    private void updateView() {

    }

    @OnClick({R.id.shareToQQ, R.id.shareToWX, R.id.cancel})
    public void onClick(View v) {
        switch (v.getId()) {
            // 分享至QQ
            case R.id.shareToQQ:
                if (Constants.ShareType.text.equals(shareType)) {
                    shareListener.startActivity(QQManager.shareText(textContent));
                } else {
                    shareListener.startActivity(QQManager.shareFile(filePath));
                }
                dismiss();
                break;
            // 分享至微信
            case R.id.shareToWX:
                if (Constants.ShareType.text.equals(shareType)) {
                    shareListener.startActivity(WXManager.shareText(textContent));
                } else {
                    shareListener.startActivity(WXManager.shareFile(filePath));
                }
                dismiss();
                break;
            // 取消
            case R.id.cancel:
                dismiss();
                break;
        }
    }

    public void setShareType(Constants.ShareType shareType) {
        this.shareType = shareType;
    }

    public void setTextContent(String textContent) {
        this.textContent = textContent;
    }

    public void setFilePath(String filePath) {
        this.filePath = filePath;
    }

    public void setShareListener(ShareListener shareListener) {
        this.shareListener = shareListener;
    }

    public interface ShareListener {
        void startActivity(Intent intent);
    }
}
